//
//  YZPersonalAPI.m
//  VET
//
//  Created by 刘文靖 on 2018/7/4.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZPersonalAPI.h"
#import "YZUser.h"
#import "YZNetworkManager.h"
@implementation YZPersonalAPI
+ (RACSignal*)uploadCertificate:(UIImage*)image{
    
    YZPersonalAPI *api = [YZPersonalAPI api];
    api.action = [NSString stringWithFormat:@"/api/profession/certificate/%@",[YZUser sharedInstance].uid];
    api.showLoadingStatus = YES;
    
    return [api uploadCertificate:image];
}


/**兽医个人基本信息 */
+ (RACSignal*)requestPersonalBaseInfo{
    
    YZPersonalAPI *api = [YZPersonalAPI api];
    api.action = [NSString stringWithFormat:@"/api/personCenter/my/baseInfo/%@",[YZUser sharedInstance].uid];
    api.showLoadingStatus = NO;
    
    return [api getRequest];
}

/**修改密码,获取短信验证码 */
+ (RACSignal*)requestMessageForPWD:(NSString *)mobile{
    YZPersonalAPI *api = [YZPersonalAPI api];
    api.action = [NSString stringWithFormat:@"/api/user/messageForPwd/%@",mobile];
    api.showLoadingStatus = YES;
    return [api getRequest];
}

/**修改密码,需要传入验证码,手机号,密码(此处传明文) */
+ (RACSignal*)modifyPassword:(NSString *)newPWD mobile:(NSString *)mobile verCode:(NSString *)verCod{
    YZPersonalAPI *api = [YZPersonalAPI api];
    api.action = @"/api/user/password";
    [api addParams:@{
                     @"mobile" : mobile,
                     @"password": newPWD,
                     @"uniqueId": [YZUser sharedInstance].uniqueId?:@"",
                     @"userType": @"mobile",
                     @"verCode": verCod
                     }];
    api.showLoadingStatus = YES;
    
    return [api patchRequest];
}

/**兽医职业类型,返回String集合*/
+ (RACSignal*)requestProfessionTypeArr{
    YZPersonalAPI *api = [YZPersonalAPI api];
    api.action = @"/api/user/professionType";
    api.showLoadingStatus = YES;
    return [api getRequest];
}

/**个人中心-设置-用户反馈*/
+ (RACSignal*)submitFeedback:(NSString *)feedbackType content:(NSString *)content{
    YZPersonalAPI *api = [YZPersonalAPI api];
    api.action = @"/api/personCenter/my/feedback";
    api.showLoadingStatus = YES;
    [api addParam:@"vetId" value:[YZUser sharedInstance].uid];
    [api addParam:@"feedbackType" value:feedbackType];
    if (content) {
        [api addParam:@"content" value:content];
    }
    return [api postRequest];
}

- (RACSignal*)uploadCertificate:(UIImage*)image {
    
    return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        
        // 是否显示菊花
        [self requestBegin];
        NSString *url = [NSString stringWithFormat:@"%@%@", self.urlDomain, self.action];
        [[[YZNetworkManager sharedInstance] uploadImgWithUrl:url params:nil withHeaders:self.headerParams img:image imgPath:@"files" apiKey:@""] subscribeNext:^(id  _Nullable data) {
            
            [subscriber sendNext:data];
            
        } error:^(NSError * _Nullable error) {
            
#ifdef DEBUG
            // debug 时 显示错误信息
            [self showErrorInfo:error];
#endif
            [self requestEnd];
            [subscriber sendError:error];
            
        } completed:^{
            
            [self requestEnd];
            [subscriber sendCompleted];
        }];
        
        return [RACDisposable disposableWithBlock:^(){}];
    }];
}
@end
